<template>
  <div id="register">
  <div class="header">
    <img src="../img/left.png" @click="back">
    <h4>注册</h4>
  </div>
  <div class="Info">
    <div class="user-Info">
      <input type="text" placeholder="请输入用户名"  id="userName" ref="userName"/>
      <!--<input type="text" placeholder="请输入手机号码"  id="userPhone"/>-->
      <input type="password" placeholder="请输入密码"  id="userPwd" ref="pwd"/>
      <input type="password" placeholder="推荐人id"  id="refereeId" ref="refereeId"/>
    </div>
  </div>
  <div class="button" style="margin-top: 10px" @click="commit">提交</div>
  <span class="register-tips">{{tips}}</span>
  </div>
</template>

<script>
    export default {
     name:'register',
        data() {
            return {
              tips:"",

            }
        },
        methods: {
          back(){
            this.goback()
          },
          commit(){
            var reg = /^1[0-9]{10}$/;
            var name=this.$refs.userName.value;
            var pwd=this.$refs.pwd.value;
            var refereeId=this.$refs.refereeId.value;
            if(name.length == '0'){
             this.tips='用户名不能为空';
            }else if(pwd.length == '0'){
              this.tips='密码不能为空'
            }else if(pwd.length < 6){
              this.tips='密码长度不能小于6位'
            }else {
              this.tips='';
              var sendJSON={};
              sendJSON.loginName=name;
              sendJSON.loginPwd=pwd;
              sendJSON.refereeId=refereeId;
              this.$http.post(this.urlHost+'user/register.do',JSON.stringify(sendJSON),{
                emulateJSON:true
              }).then(function(res){
                // alert(JSON.stringify(res))
                if(res.body.code!="0000"){
                  //alert(res.body.errMsg)
                  this.tips=res.body.errMsg;
                }else{
                  this.tips="注册成功!";
                  setTimeout(() => {
                    this.$router.push({path: 'login'});
                  }, 1000);

                }
              },function(res){
               alert(res)
              });

            }
          }
        }
    }
</script>
<style>
</style>
